// 侧边栏多层列表
(function($) {
    $.expr[":"].Contains = function(a, i, m) {
        return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
    };
    function filterList(header, list) {
        //@header 头部元素
        //@list 无需列表
        //创建一个搜素表单
        var form = $("<form>").attr({
            "class":"filterform",
            action:"#"
        }), input = $("<input>").attr({
            "class":"filterinput",
            type:"text"
        });
        $(form).append(input).appendTo(header);
        $(input).change(function() {
            var filter = $(this).val();
            if (filter) {
                $matches = $(list).find("a:Contains(" + filter + ")").parent();
                $("li", list).not($matches).slideUp();
                $matches.slideDown();
            } else {
                $(list).find("li").slideDown();
            }
            return false;
        }).keyup(function() {
            $(this).change();
        });
    }
    $(function() {
        filterList($("#form"), $("#demo-list"));
    });
})(jQuery);


$(function(){
    var form;
    var birth = sessionStorage.getItem("birth");
    var sub_employee_id;
    if(birth == 'null' || birth == undefined || birth == '') {
        birth = '';
    }

    layui.config({
        version: false,
        debug: false,
        base: 'layui/modules/'
    }).use('global'); //加载入口

    layui.use(['element', 'carousel', 'form', 'laydate'], function(){
        var element = layui.element;
        var carousel = layui.carousel;
        form = layui.form;
        var laydate = layui.laydate;

        //建造实例
        carousel.render({
            elem: '#carousel',
            width: '94%',
            height: '20rem',
            arrow: 'hover'
        });
        laydate.render({
            elem: '#birth'
            ,value: birth
            ,max:methods.get_now_format_date()
        });
        laydate.render({
            elem: '#select_plan'
            ,value: ''
            ,max:methods.get_now_format_date()
        });
        element.on('tab(test)', function(data){
            // alert(this); //当前Tab标题所在的原始DOM元素
            // alert(data.elem.html()); //得到当前的Tab大容器
            var index = data.index; //得到当前Tab的所在下标
            sub_employee_id = this.getAttribute('name');
            var today = methods.get_now_format_date();
            var yesterday = methods.get_yesterday_format_date(today, 1);
            methods.get_yesterday_plan_list(sub_employee_id,yesterday,index);
            methods.get_yesterday_comment(sub_employee_id, yesterday);
        });
    });

    jQuery("#jquery-accordion-menu").jqueryAccordionMenu();

    var main = $('body');
    var user_name = sessionStorage.getItem("user_name");
    var user_id = sessionStorage.getItem("user_id");
    var user_phone = sessionStorage.getItem("user_phone");
    var credit_score = parseInt(sessionStorage.getItem("credit_score"));
    var resume_image = sessionStorage.getItem("resume_image");
    var gender = sessionStorage.getItem("gender");

    var company_name, department_name, duty, plan_id;

    $('#user_name').text(user_name);
    $('.s-home .user_name').text(user_name);
    $('.score').text(credit_score);

    // 是否是公司员工-获取公司名字
    if(sessionStorage.getItem("company_name")){
        company_name = sessionStorage.getItem("company_name");
        if(company_name != ''){
            $('.company_name').text(company_name);
            $('.company').append(company_name);
        }
    }else {
        $('.content').css('display','none');
        $('#pool-item-3').css('display','none');
        $('#pool-item-4').css('display','none');
    }

    // 是否是公司员工-获取部门名字
    if(sessionStorage.getItem("department_name")){
        department_name = sessionStorage.getItem("department_name");
        if(department_name != ''){
            $('.department_name').text(department_name);
        }
    }

    // 是否是公司员工-获取职务
    if(sessionStorage.getItem("duty")){
        duty = sessionStorage.getItem("duty");
        if(duty == 'undefined' || duty == '' || duty == 'null'){
            $('.duty').text('');
        }else{
            $('.duty').text('职务：'+duty);
        }
    }

    // 判断是否已提交过过往简历
    if(resume_image == 'undefined' || resume_image == '' || resume_image == 'null'){
        $('.goto_resume').css('display','block');
    }else{
        $('.goto_resume').css('display','none');
    }

    //初始化
    $(".s-pool .s-right").children().eq(0).css("display","block").siblings().css("display","none");
    $(".s-data .s-right").children().eq(0).css("display","block").siblings().css("display","none");
    $(".s-setting .s-right").children().eq(0).css("display","block").siblings().css("display","none");
    $(".s-home").siblings('section').css('display','none');

    $(".header-container div").click(function () {
        if($(this).attr('class') == 'home' || $(this).attr('class') == 'company_name'){
            $(this).siblings().css({'borderBottom':'none','color':'#000'});
            $('.s-' + $(this).attr('class')).css('display','block')
                .siblings().css('display','none');
        }else{
            $(this).css({'borderBottom':'0.2rem inset #3296FA','color':'#3296FA'})
                .siblings().css({'borderBottom':'none','color':'#000'});
            $('.s-' + $(this).attr('class')).css('display','block')
                .siblings().css('display','none');
        }
    });

    //用于控制左边导航栏
    $(".s-left .sub-menu-select-item").click(function () {
        $(".s-right"+" .s-"+$(this).attr("id")).css("display","block").siblings().css('display','none');
        $(this).addClass("s-left-first").siblings().removeClass("s-left-first");
    });

    // 点击右上角的叉
    main.on("click", ".background_img i", function () {
        $('.background_img').css('display','none');
        $('#carousel').css('display','block');
    });

    // 点击右上角的名字
    main.on("click", "#user_name", function () {
        $('.setting').css({'borderBottom':'0.2rem inset #3296FA','color':'#3296FA'})
            .siblings().css({'borderBottom':'none','color':'#000'});
        $('.s-' + $('.setting').attr('class')).css('display','block')
            .siblings().css('display','none');
    });

    // 点击右上角的注销
    main.on("click", "#logout", function () {
        sessionStorage.clear();
        window.location.href='./index.html';
    });

    //点击通讯录
    main.on("click", ".content", function (){
        $('.department_name').html(company_name);
        methods.get_company_structure(user_id);
        $('#demo-list').html('<li class="active" name=0 onclick="methods.click_department(this)"><a href="#" class="company"><i class="fa fa-home"></i></a></li>');
        $('.company').append(company_name);
    });

    // 通讯录的部门表格行点击事件
    $('.sub_department table.layui-table').click(function(event){
        var cells = $(event.target).closest("tr")[0].getElementsByTagName("td"); // 找到这个tr下的所有td，不能用childNodes 属性，部分浏览器不兼容
        for(var i=0;i<cells.length;i++) {
            alert(cells[i].innerHTML);
        }
    });

    //点击工作池
    main.on("click", ".pool", function (){
        var now_format_date = methods.get_now_format_date();
        $('.pool_header span').html(now_format_date);
        methods.get_plan_list(user_id, now_format_date);
        $('.s-pool-item-3 .pool_header span').html('昨日：' + methods.get_yesterday_format_date(now_format_date,1));
    });

    //点击工作池-1.进度列表
    main.on("click", "#pool-item-1", function (){
        var now_format_date = methods.get_now_format_date();
        $('.pool_header span').html(now_format_date);
        methods.get_plan_list(user_id, now_format_date);
    });

    //点击工作池-1.进度列表-添加新计划按钮
    main.on("click", ".s-pool .add_plan", function (){
        $('.s-pool-item-1 .layui-form').css('display','block');
    });

    //点击工作池-1.进度列表-确认提交今日计划按钮
    main.on("click", ".s-pool .submit_plan", function (){
        layer.open({
            title: '确认框',
            content: '确认提交后，您还能修改今日计划，但是将对您的信用分不产生任何影响，是否确认提交？'
            ,btn: ['确认', '取消']
            ,yes: function(index, layero){
                methods.submit_today_plan(user_id);
            }
            ,btn2: function(index, layero){
                //return false 开启该代码可禁止点击该按钮关闭
            }
            ,cancel: function(){
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
    });

    //点击工作池-1.进度列表-确认添加按钮
    main.on("click", ".s-pool #add_plan", function (){
        var content = $('#plan_content').val();
        if(content == ''){
            layer.msg('请输入计划内容...');
        }else {
            methods.add_plan(user_id, content);
            var now_format_date = methods.get_now_format_date();
            methods.get_plan_list(user_id, now_format_date);
            $('#plan_content').val('');
        }
    });

    // 计划的编辑按钮
    main.on("click", ".s-pool-item-1 .edit_pool", function (e){
        plan_id = $(e.target).attr('name');
        var old_content = $(e.target).parent().parent().find('.plan_content').html();
        var old_is_finished = $(e.target).parent().parent().find('.plan_is_finished').html();
        $('#old_plan_content').val(old_content);
        if(old_is_finished == '已完成'){
            $('#selsect_is_finished').val('1');
            form.render('select','selFilter');
        }else{
            $('#selsect_is_finished').val('0');
            form.render('select','selFilter');
        }
    });

    //点击工作池-1.进度列表-立即修改按钮
    main.on("click", ".s-pool #edit_plan", function (){
        var content = $('#old_plan_content').val();
        var is_finished = $('#selsect_is_finished').val();
        if(is_finished == '0'){
            is_finished = 'False';
        }else{
            is_finished = 'True';
        }
        if(content == ''){
            layer.msg('请输入计划内容...');
        }else {
            methods.edit_plan(plan_id, content, is_finished);
            $('#myModal').modal('hide');
            var now_format_date = methods.get_now_format_date();
            methods.get_plan_list(user_id, now_format_date);
        }
    });

    //点击工作池-2.个人评价
    main.on("click", "#pool-item-2", function (){
        var now_format_date = methods.get_now_format_date();
        $('.add_comment').css('display','none');
        $('.pool_header span').html(now_format_date);
        methods.get_plan_list(user_id, now_format_date);
        methods.search_comment(user_id, now_format_date);
    });

    //点击工作池-2.个人评价-搜索按钮
    main.on("click", ".s-pool-item-2 .search_btn", function (){
        var date = $('#select_plan').val();
        if(date == ''){
            layer.msg('请选择要搜索的日期...');
        }else {
            $('.pool_header span').html(date);
            methods.get_plan_list(user_id, date);
            methods.search_comment(user_id, date);
            $('#select_plan').val('');
        }
    });

    //点击工作池-3.评价下级
    main.on("click", "#pool-item-3", function (){
        var now_format_date = methods.get_now_format_date();
        methods.get_sub_employee(user_id);
        $('.s-pool-item-3 .pool_header span').html('昨日：' + methods.get_yesterday_format_date(now_format_date,1));
    });

    //点击工作池-3.评价下级-添加评价
    main.on("click", "#submit_comment", function (){
        var comment_content = $("#yesterday_content").val();
        var comment_score = $('.fenshu').html();
        if (comment_content == ''){
            layer.msg('请输入评价内容...');
        }else if(comment_score == ''|| comment_score == 0){
            layer.msg('请进行星级评价...');
        } else {
            var today = methods.get_now_format_date();
            var yesterday = methods.get_yesterday_format_date(today, 1);
            methods.add_comment(yesterday,sub_employee_id,comment_content,comment_score/10,user_id);
            $('#yesterday_comment').modal('hide');
            methods.get_yesterday_comment(sub_employee_id, yesterday);
        }
    });

    //点击工作池-4.员工查询
    main.on("click", "#pool-item-4", function (){
        var company_id = sessionStorage.getItem("company_id");
        methods.get_employee_list(company_id);
    });

    //点击工作池-4.员工查询-搜索按钮
    main.on("click", ".s-pool-item-4 .search_btn", function (){
        var search_name = $('#search_employee').val();
        var company_id = sessionStorage.getItem("company_id");
        if(search_name == ''){
            methods.get_employee_list(company_id);
        }else{
            methods.search_employee(company_id,search_name);
        }
    });

    //点击工作池-4.员工查询-查看按钮
    main.on("click", ".search_employee_list .employee_info", function (e){
        var search_user_id = $(e.target).attr('name');
        // $('.search_reward').attr("name",search_user_id);
        $('#get_user_name').val('');
        $('#get_user_phone').val('');
        $('#get_user_department').val('');
        $('#get_user_duty').val('');
        $('#get_user_gender').val('');
        $('#get_user_birth').val('');
        methods.get_user_info(search_user_id);
    });

    //点击工作池-5.公司查询
    main.on("click", "#pool-item-5", function (){
        methods.get_company_list('');
    });

    //点击工作池-5.公司查询-搜索按钮
    main.on("click", ".s-pool-item-5 .search_btn", function (){
        var search_name = $('#search_company').val();
        methods.get_company_list(search_name);
    });

    // //点击工作池-5.企业查询-查看按钮
    // main.on("click", "#pool-item-5", function (){
    //
    // });

    //点击个人数据的-1.使用统计
    main.on("click", ".data", function (){
        methods.get_join_sys_days(user_id);
        if(sessionStorage.getItem("company_name")) {
            methods.get_join_comp_days(user_id);
        }else{
            $('#join_comp_days').html('您还未加入公司...');
        }
       methods.draw_count_table(user_id);
    });

    //点击个人数据-2.评价统计
    main.on("click", ".s-data #data-item-2", function (){
        methods.draw_finished_rate_table(user_id);
        methods.draw_star_rate_table(user_id);
        });

    //点击个人数据-3.个人信用
    main.on("click", ".s-data #data-item-3", function (){
        methods.draw_credit_table(user_id);
    });

    //点击个人数据-4.个人信用
    main.on("click", ".s-data #data-item-4", function (){
        if(resume_image == 'undefined' || resume_image == '' || resume_image == 'null'){
            $('.resume_img').html('<p>当前您尚未添加过往简历，点击下方按钮去补全...</p>');
            $('.edit_resume').html('添加简历');
        }else{
            $('.resume_img').html('<p>点击图片放大预览</p>' +
                '<div id="layer-photos-demo" class="layer-photos-demo">\n' +
                '  <img layer-src="'+resume_image+'" src="'+resume_image+'" alt="个人简历">\n' +
                '</div>');
            $('.edit_resume').html('编辑简历');
        }
        methods.get_sys_resume(user_id);
    });

    //点击个人数据-4.个人简历-点击图片放大
    main.on("click", ".s-data img", function (){
        layer.photos({
            photos: '#layer-photos-demo'
            ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        });
    });

    //点击个人数据-4.个人简历-添加/编辑简历按钮
    main.on("click", ".s-data .edit_resume", function (){

    });

    // 点击设置-1.个人信息
    main.on("click", ".setting", function (){
        $('.s-setting #name').val(user_name);
        $('.s-setting .user_phone').val(user_phone);
        if(gender == '女'){
            $('#gender').val('0');
            form.render('select','selFilter');
        }else if(gender == '男'){
            $('#gender').val('1');
            form.render('select','selFilter');
        } else{
            $('#gender').val('');
            form.render('select','selFilter');
        }
    });

    // 点击设置-1.个人信息-提交修改
    main.on("click", ".edit_personal", function (){
        form.render('select','selFilter');
        var gender_value = $("#gender").val();
        var new_name = $("#name").val();
        var new_image = '';
        var new_birth = $("#birth").val();
        if(gender_value == '0'){
            gender_value = '女'
        }else if(gender_value == '1'){
            gender_value = '男'
        }else{}
        methods.edit_personal(user_id, new_name, new_image, gender_value, new_birth);
        user_name = new_name;
        birth = new_birth;
        gender = gender_value;
        $('#user_name').text(new_name);
        $('.s-home .user_name').text(new_name);
        $('.s-setting #name').val(new_name);
        laydate.render({
            elem: '#birth'
            ,value: new_birth
        });
        return false;
    });

    // 点击设置-2.修改密码-提交修改
    main.on("click", ".change_password", function (){
        var old_password = $("#old_password").val();
        var new_password = $("#new_password").val();
        if(old_password == ''){
            layer.msg('请输入旧密码...');
        }else if(new_password == ''){
            layer.msg('请输入新密码...');
        }else{
            methods.change_password(user_id,old_password,new_password);
        }
        return false;
    });
});


var methods = {

    // 获取当前日期
    get_now_format_date: function () {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    },

    // 获取当前日期前一天
    get_yesterday_format_date:function (dateParameter, num) {
        var translateDate = "", dateString = "", monthString = "", dayString = "";
        translateDate = dateParameter.replace("-", "/").replace("-", "/");
        var newDate = new Date(translateDate);
        newDate = newDate.valueOf();
        newDate = newDate - num * 24 * 60 * 60 * 1000;
        newDate = new Date(newDate);
        //如果月份长度少于2，则前加 0 补位
        if ((newDate.getMonth() + 1).toString().length == 1) {
            monthString = 0 + "" + (newDate.getMonth() + 1).toString();
        } else {
            monthString = (newDate.getMonth() + 1).toString();
        }
        //如果天数长度少于2，则前加 0 补位
        if (newDate.getDate().toString().length == 1) {
            dayString = 0 + "" + newDate.getDate().toString();
        } else {
            dayString = newDate.getDate().toString();
        }
        dateString = newDate.getFullYear() + "-" + monthString + "-" + dayString;
        return dateString;
    },

    // 获取当前时间
    // get_now_format_time: function () {
    //     var date = new Date();
    //     var seperator1 = "-";
    //     var seperator2 = ":";
    //     var month = date.getMonth() + 1;
    //     var strDate = date.getDate();
    //     if (month >= 1 && month <= 9) {
    //         month = "0" + month;
    //     }
    //     if (strDate >= 0 && strDate <= 9) {
    //         strDate = "0" + strDate;
    //     }
    //     var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    //         + " " + date.getHours() + seperator2 + date.getMinutes()
    //         + seperator2 + date.getSeconds();
    //     return currentdate;
    // },

    // 获取公司一级部门
    get_company_structure: function (user_id) {
        $.ajax({
            type: 'get',
            url: 'http://106.15.196.50:8888/company_structure?user_id='+user_id,
            timeout: 6000,
            dataType: 'json',
            success: function(json){
                $('.department_name').html(sessionStorage.getItem("company_name"));
                if(json.code == 200){
                    if(json.msg == '获取公司一级部门...'){
                        for (var i=0;i < json.data.sub_department.length;i++){
                            var department_name=json.data.sub_department[i].department_name;
                            var department_id=json.data.sub_department[i].department_id;
                            if (json.data.sub_department[i].sum_sub_department > 0){
                                $('#demo-list').append('<li name='+department_id+' onclick="methods.click_department(this)"><a href="#">'+department_name+'</a><ul class="submenu"></ul></li>');
                            }else{
                                $('#demo-list').append('<li name='+department_id+' onclick="methods.click_department(this)"><a href="#">'+department_name+'</a></li>');
                            }
                        }
                        $('.sub_department tbody').html(template('sub_departmrnt',json.data.sub_department));
                        if (json.data.employee.length == 0){
                            $('.employee tbody').html('该部门还未有成员...');
                        }else{
                            $('.employee tbody').html(template('employee',json.data.employee));
                        }
                    }else {
                        $('.sub_department tbody').html('该公司还未有子部门...');
                        if (json.data.employee.length == 0){
                            $('.employee tbody').html('该部门还未有成员...');
                        }else{
                            $('.employee tbody').html(template('employee',json.data.employee));
                        }
                    }
                }else {
                    layer.open({
                        title: '错误',
                        content: json.msg
                    });
                }
            },
            error: function(){
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 点击部门获取子部门和部门成员
    get_department_structure:function (department_id) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/company_structure/',
            timeout: 6000,
            data: {
                department_id: department_id
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    if (json.data.sub_department.length == 0){
                        $('.sub_department tbody').html('该部门还未有子部门...');
                    }else{
                        $('.sub_department tbody').html(template('sub_departmrnt',json.data.sub_department));
                    }
                    if (json.data.employee.length == 0){
                        $('.employee tbody').html('该部门还未有成员...');
                    }else{
                        $('.employee tbody').html(template('employee',json.data.employee));
                    }
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        })
    },

    // 点击部门获取子部门和部门成员
    click_department:function (that) {
        $("#demo-list li.active").removeClass("active");
        $(that).addClass("active");
        var department_id = $(that).attr('name');

        $('.department_name').html($(that).text());
        if (department_id == 0){
            $('.department_name').html(sessionStorage.getItem("company_name"));
            methods.get_company_structure(sessionStorage.getItem("user_id"));
            $('#demo-list').html('<li class="active" name=0 onclick="methods.click_department(this)"><a href="#" class="company"><i class="fa fa-home"></i></a></li>');
            $('.company').append(sessionStorage.getItem("company_name"));
        }else {
            methods.get_department_structure(parseInt(department_id));
        }
    },

    // 获取计划列表
    get_plan_list:function (user_id, date) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/search_plan/',
            timeout: 6000,
            data: {
                user_id: user_id,
                date: date
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    $('.s-pool-item-1 .today_list div').html(template('plan_list',json.data.plan));
                    $('.s-pool-item-2 .old_list div').html(template('yesterday_plan',json.data.plan));
                }else{
                    $('.s-pool-item-1 .today_list div').html(json.msg);
                    $('.s-pool-item-2 .old_list div').html(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        })
    },

    // 获取昨日计划列表
    get_yesterday_plan_list:function (user_id, date, index) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/search_plan/',
            timeout: 6000,
            data: {
                user_id: user_id,
                date: date
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    $('.s-pool-item-3 .layui-tab-content').children('.layui-tab-item').eq(index).html(template('yesterday_plan',json.data.plan));
                }else{
                    $('.s-pool-item-3 .layui-tab-content').children('.layui-tab-item').eq(index).html(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        })
    },

    // 添加新计划
    add_plan:function (user_id, content) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/add_delete_plan/',
            timeout: 6000,
            data: {
                user_id: user_id,
                content: content
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    layer.msg(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        })
    },

    // 编辑计划
    edit_plan:function (plan_id, content, is_finished) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/edit_plan/',
            timeout: 6000,
            data: {
                plan_id: plan_id,
                content: content,
                is_finished: is_finished
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    layer.msg(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 删除计划
    delete_plan:function (that) {
        var plan_id = $(that).attr('name');
        $.ajax({
            type: 'get',
            url: 'http://106.15.196.50:8888/add_delete_plan?plan_id=' + plan_id,
            timeout: 6000,
            dataType: 'json',
            success: function (json) {
                layer.msg(json.msg);
                var user_id = sessionStorage.getItem("user_id");
                var now_format_date = methods.get_now_format_date();
                methods.get_plan_list(user_id,now_format_date)
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 提交今日计划
    submit_today_plan:function (user_id) {
        $.ajax({
            type: 'get',
            url: 'http://106.15.196.50:8888/edit_plan?user_id=' + user_id,
            timeout: 6000,
            dataType: 'json',
            success: function (json) {
                if(json.code == 200){
                    layer.msg(json.msg);
                    $('.score').text(json.data.score_int);
                    sessionStorage.setItem("credit_score",json.data.score_int);
                }else{
                    layer.msg(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 查询某日评价
    search_comment:function (user_id,date) {
        $.ajax({
            type: 'get',
            url: 'http://106.15.196.50:8888/add_search_comment?user_id='+user_id+'&date='+date,
            timeout: 6000,
            dataType: 'json',
            success: function (json) {
                if (json.code == 200){
                    $('.comment .comment_msg').css('display','none');
                    $("#superior").val(json.data.superior);
                    $("#content").val(json.data.content);
                    $("#superior").val(json.data.superior);
                    $('.comment form').css('display','block');
                    $(".s-pool-item-2 .show_number li p").each(function(index, element) {
                        $(this).attr("tip",json.data.star_rate*10);
                        var num=$(this).attr("tip");
                        var www=num*16;//
                        $(this).css("width",www);
                        $(this).parent(".atar_Show").siblings("span").text(num+"分");
                    });
                }else{
                    $('.add_comment').css('display','none');
                    $('.comment form').css('display','none');
                    $('.comment .comment_msg').css('display','block');
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 查询昨日评价，评价下级
    get_yesterday_comment:function (user_id,date) {
        $.ajax({
            type: 'get',
            url: 'http://106.15.196.50:8888/add_search_comment?user_id='+user_id+'&date='+date,
            timeout: 6000,
            dataType: 'json',
            success: function (json) {
                if (json.code == 200){
                    $('.add_comment').css('display','block');
                    $('.add_comment').html('查看评价');
                    $('.s-pool-item-3 .modal .modal-title').html('查看评价');
                    $('.s-pool-item-3 .modal .layui-input-block button').css('display','none');

                    $('.s-pool-item-3 .modal .layui-input-block #startone').css('display','none');
                    $('.s-pool-item-3 .modal .layui-input-block ul').css('display','block');
                    $("#yesterday_content").val(json.data.content);
                    $(".s-pool-item-3 .show_number li p").each(function(index, element) {
                        $(this).attr("tip",json.data.star_rate*10);
                        var num=$(this).attr("tip");
                        var www=num*16;//
                        $(this).css("width",www);
                        $(this).parent(".atar_Show").siblings("span").text(num+"分");
                    });
                }else{
                    $("#yesterday_content").val('');
                    $('.add_comment').css('display','block');
                    $('.add_comment').html('添加评价');
                    $('.s-pool-item-3 .modal .modal-title').html('添加评价');
                    $('.s-pool-item-3 .modal .layui-input-block button').css('display','block');

                    $('.s-pool-item-3 .modal .layui-input-block #startone').css('display','block');
                    $('.s-pool-item-3 .modal .layui-input-block ul').css('display','none');
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 添加新评价
    add_comment:function (date,sub_employee_id,content,star_rate,user_id) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/add_search_comment/',
            timeout: 6000,
            data: {
                date: date,
                user_id: sub_employee_id,
                content: content,
                star_rate: star_rate,
                superior_id: user_id
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    layer.msg(json.msg);
                }else{
                    layer.msg(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        })
    },
    
    // 获取下级员工
    get_sub_employee:function (user_id) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/get_sub_employee/',
            timeout: 6000,
            data: {
                user_id: user_id,
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    $('.s-pool-item-3 .layui-tab').html(template('sub_employees',json.data.sub_employee));
                }else{
                    layer.msg(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        })
    },

    // 获取公司员工列表
    get_employee_list:function (company_id) {
        $.ajax({
            type: 'get',
            url: 'http://106.15.196.50:8888/search_employee?company_id=' + company_id,
            timeout: 6000,
            dataType: 'json',
            success: function (json) {
                $('.search_employee_list div').html(template('search_employee_list',json.data.company));
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 根据名字搜索员工
    search_employee:function (company_id,name) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/search_employee/',
            timeout: 6000,
            data: {
                company_id: company_id,
                name: name
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    $('.search_employee_list div').html(template('search_employee_list',json.data.company));
                }else{
                    $('.search_employee_list div').html(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        })
    },

    // 查看员工信息
    get_user_info:function (user_id) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/get_user/',
            timeout: 6000,
            data: {
                user_id: user_id
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    $('#get_user_name').val(json.data.name);
                    $('#get_user_phone').val(json.data.phone);
                    $('#get_user_department').val(json.data.department_name);
                    $('#get_user_duty').val(json.data.duty);
                    $('#get_user_gender').val(json.data.gender);
                    $('#get_user_birth').val(json.data.birth);
                    if(json.data.resume_image == '' || json.data.resume_image == null){
                        $('.get_resume').css('display','none');
                    }else{
                        $('.get_resume').css('display','inline-block');
                        $('#layer-photos-demo1 img').attr("layer-src",json.data.resume_image);
                        $('#layer-photos-demo1 img').attr("src",json.data.resume_image);
                        layer.photos({
                            photos: '#layer-photos-demo1'
                            ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                        });
                    }
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        })
    },

    // 获取公司列表/根据公司名搜索公司
    get_company_list:function (company_name) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/search_company/',
            timeout: 6000,
            data: {
                company_name: company_name
            },
            dataType: 'json',
            success: function(json){
                if(json.code == 200) {
                    $('.search_company_list div').html(template('search_company_list',json.data.company));
                }else{
                    $('.search_company_list div').html(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        })
    },

    // 获取加入系统的天数
    get_join_sys_days:function (user_id) {
        $.ajax({
            type: 'get',
            url: 'http://106.15.196.50:8888/join_days?user_id=' + user_id,
            timeout: 6000,
            dataType: 'json',
            success: function (json) {
                $('#join_sys_days').html(json.data.join_days);
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 获取加入企业的天数
    get_join_comp_days:function (user_id) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/join_days/',
            timeout: 6000,
            data: {
                user_id: user_id
            },
            dataType: 'json',
            success: function (json) {
                $('#join_comp_days').html(json.data.join_days);
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 绘制个人登录统计表
    draw_count_table:function (user_id){
        $.getJSON('http://106.15.196.50:8888/user_login/?user_id='+user_id, function (data) {
            if(data.code !== 200) {
                alert('获取登录数据失败！');
                return false;
            }else{
                data = data.data.count;
                Highcharts.stockChart('c1', {
                    title: {
                        text: '登录情况统计表'
                    },
                    series: [{
                        name: '登录次数',
                        data: data
                    }]
                });
            }
        });
    },

    // 绘制完成率统计表
    draw_finished_rate_table:function (user_id){
        $.getJSON('http://106.15.196.50:8888/sum_rate/?user_id='+user_id, function (data) {
            if(data.code == 400) {
                $('#c2').html(data.msg);
            }else if(data.code == 200){
                data = data.data.finished_rate;
                Highcharts.stockChart('c2', {
                    title: {
                        text: '计划完成率统计表'
                    },
                    series: [{
                        name: '完成率',
                        data: data
                    }]
                });
            }else{
                alert('获取计划完成率数据失败！');
                return false;
            }
        });
    },

    // 绘制星级评价统计表
    draw_star_rate_table:function (user_id){
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/sum_rate/',
            timeout: 6000,
            data: {
                user_id: user_id
            },
            dataType: 'json',
            success: function (json) {
                if(json.code == 400) {
                    $('#c3').html(json.msg);
                }else if(json.code == 200){
                    var data = json.data.star_rate;
                    Highcharts.stockChart('c3', {
                        title: {
                            text: '星级评价统计表'
                        },
                        series: [{
                            name: '星级评价',
                            data: data
                        }]
                    });
                }else{
                    alert('获取星级评价数据失败！');
                    return false;
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 绘制个人信用统计表
    draw_credit_table:function (user_id){
        $.getJSON('http://106.15.196.50:8888/personal_credit?user_id='+user_id, function (data) {
            if(data.code == 200){
                data = data.data.credit;
                Highcharts.stockChart('c4', {
                    title: {
                        text: '个人信用统计表'
                    },
                    series: [{
                        name: '信用分',
                        data: data
                    }]
                });
            }else{
                alert('获取个人信用数据失败！');
                return false;
            }
        });
    },

    // 获取系统历史简历列表
    get_sys_resume:function (user_id) {
        $.ajax({
            type: 'get',
            url: 'http://106.15.196.50:8888/edit_resume?user_id=' + user_id,
            timeout: 6000,
            dataType: 'json',
            success: function (json) {
                if(json.code == 200) {
                    $('.sys_resume tbody').html(template('sys_resume',json.data.sys_resume));
                }else{
                    $('.sys_resume tbody').html(json.msg);
                }
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 修改个人信息
    edit_personal:function (user_id, name, image, gender, birth) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/personal_setting/',
            timeout: 6000,
            data: {
                user_id: user_id,
                name: name,
                image: image,
                birth: birth,
                gender: gender
            },
            dataType: 'json',
            success: function (json) {
                sessionStorage.setItem("user_name",json.data.name);
                sessionStorage.setItem("image",json.data.image);
                sessionStorage.setItem("birth",json.data.birth);
                sessionStorage.setItem("gender",json.data.gender);
                layer.msg(json.msg);
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    },

    // 修改登录密码
    change_password:function (user_id, old_password, new_password) {
        $.ajax({
            type: 'post',
            url: 'http://106.15.196.50:8888/change_password/',
            timeout: 6000,
            data: {
                user_id: user_id,
                old_password: old_password,
                new_password: new_password
            },
            dataType: 'json',
            success: function (json) {
                    $("#old_password").val('');
                    $("#new_password").val('');
                    layer.msg(json.msg);
            },
            error: function () {
                layer.open({
                    title: '错误',
                    content: '请求服务器错误，请重试...'
                });
            }
        });
    }
};